package com.siwei.mes.entity;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.validator.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 试验台账json详情(ExperimentDetail)实体类
 *
 * @author linzi
 * @since 2023-12-27 23:30:45
 */
@Data
@Accessors(chain = true)
@Table(name = "t_experiment_detail")
@ApiModel(value = "ExperimentDetail", description = "试验台账json详情")
public class ExperimentDetail implements Serializable {
    private static final long serialVersionUID = -75833960579418596L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "试验台账json详情主键ID", name = "id")
    @NotNull(groups = {UpdateGroup.class}, message = "主键id为空")
    private Long id;
    /**
     * 试验台账id
     */
    @Column(name = "experiment_id")
    @ApiModelProperty(value = "试验台账id", name = "experimentId")
    @NotNull(groups = {UpdateGroup.class}, message = "试验台账id为空")
    private Long experimentId;
    /**
     * 检查类型 1-快检 2-批检
     */
    @Column(name = "check_type")
    @ApiModelProperty(value = "检查类型 1-快检 2-批检", name = "checkType")
    @NotNull(groups = {UpdateGroup.class}, message = "检查类型为空")
    private Integer checkType;
    /**
     * 试验项目code
     */
    @Column(name = "test_project_code")
    @ApiModelProperty(value = "试验项目code", name = "testProjectCode")
    @NotBlank(groups = {UpdateGroup.class}, message = "试验项目code为空")
    private String testProjectCode;
    /**
     * 试验项目名称
     */
    @Column(name = "test_project_name")
    @ApiModelProperty(value = "试验项目名称", name = "testProjectName")
    @NotBlank(groups = {UpdateGroup.class}, message = "试验项目名称为空")
    private String testProjectName;
    /**
     * 对应json
     */
    @Column(name = "obj_json")
    @ApiModelProperty(value = "对应json", name = "objJson")
    @NotNull(groups = {UpdateGroup.class}, message = "对应json为空")
    private JSONObject objJson;
    /**
     * 对应图片  多个用逗号隔开
     */
    @Column(name = "obj_img")
    @ApiModelProperty(value = "对应图片  多个用逗号隔开", name = "objImg")
    private String objImg;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    public ExperimentDetail init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date()).setIsDel(0);
        }
        return this;
    }

    public ExperimentDetail tglInit(boolean isCreate) {
        this.setUpdateTime(new Date());
        if (isCreate) {
            this.setCreateTime(new Date()).setIsDel(0);
        }
        return this;
    }
}
